package vn.bus.bk.adapter;

import java.util.ArrayList;

import vn.bus.bk.R;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListPlaceAdapter extends ArrayAdapter<String> {
    private Context context;
    private LayoutInflater mInflater;
    private ArrayList<String> strings;
    private DisplayMetrics metrics_;

    private class Holder {
	public TextView textview;
    }

    public ListPlaceAdapter(Context context, ArrayList<String> strings,
	    DisplayMetrics metrics) {
	super(context, 0);
	this.context = context;
	this.mInflater = (LayoutInflater) this.context
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	this.strings = strings;
	this.metrics_ = metrics;
    }
    
    

    @Override
    public String getItem(int position) {
	// TODO Auto-generated method stub
	return super.getItem(position);
    }

    
    


    @Override
    public int getCount() {
	// TODO Auto-generated method stub
	return strings.size();
    }



    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
	final String str = this.strings.get(position);
	final Holder holder;

	if (convertView == null) {
	    convertView = mInflater.inflate(R.layout.list_black_text, null);

	    holder = new Holder();
	    holder.textview = (TextView) convertView
		    .findViewById(R.id.list_content);
	    convertView.setTag(holder);
	} else {
	    holder = (Holder) convertView.getTag();
	}

	holder.textview.setText(str);

	Animation animation = null;

	animation = new TranslateAnimation(metrics_.widthPixels / 2, 0, 0, 0);

	//
	// case 2:
	// animation = new TranslateAnimation(0, 0, metrics_.heightPixels,
	// 0);
	// break;
	//
	// case 3:
	// animation = new ScaleAnimation((float) 1.0, (float) 1.0,
	// (float) 0, (float) 1.0);
	// break;
	//
	// case 4:
	// // non animation
	// animation = new Animation() {
	// };
	// break;
	// }
	animation = new TranslateAnimation(metrics_.widthPixels / 2, 0, 0, 0);
	animation.setDuration(750);
	convertView.startAnimation(animation);
	animation = null;

	return convertView;
    }

}
